//    Openbravo POS is a point of sales application designed for touch screens.
//    Copyright (C) 2007-2009 Openbravo, S.L.
//    http://www.openbravo.com/product/pos
//
//    This file is part of Openbravo POS.
//
//    Openbravo POS is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    Openbravo POS is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with Openbravo POS.  If not, see <http://www.gnu.org/licenses/>.

package com.openbravo.pos.inventory;

import java.awt.Component;
import java.util.Properties;
import cn.ekuma.data.ui.swing.AbstractParentDAOJEditor;
import cn.ekuma.data.ui.swing.JChildDAOEditorPanel;
import cn.ekuma.epos.datalogic.I_DataLogicERP;
import cn.ekuma.epos.datalogic.I_DataLogicSales;
import com.openbravo.bean.Location;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.user.DirtyManager;
import com.openbravo.pos.base.AppLocal;
import com.openbravo.pos.base.AppView;
import com.openbravo.pos.inventory.model.LocationLayoutTableModel;
import javax.swing.JCheckBox;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Dimension;

/**
 *
 * @author adrianromero
 */
@SuppressWarnings("serial")
public class LocationsView extends AbstractParentDAOJEditor<Location,String>{
    
    
    private JCheckBox isCustomer;
	private JCheckBox isVirtual;
	JChildDAOEditorPanel attributeValuePanel;
	
	private JCheckBox jckScore;
	private JCheckBox jckPrefPrice;
	
	/** Creates new form LocationsEditor */
    public LocationsView(AppView app,DirtyManager dirty,I_DataLogicSales dlSales) {
    	super(dirty);
        initComponents();
        
        m_jName.getDocument().addDocumentListener(dirty);
        m_jAddress.getDocument().addDocumentListener(dirty);
        isCustomer.addActionListener(dirty);
        isVirtual.addActionListener(dirty);
        jckScore.addActionListener(dirty);
        jckPrefPrice.addActionListener(dirty);
        writeValueEOF();
        attributeValuePanel=new  JChildDAOEditorPanel(dlSales,new LocationLayoutTableModel(),new JLocationLayoutEditor(app, new DirtyManager(), false, dlSales));
        add(attributeValuePanel,BorderLayout.CENTER);
        addObjectChangeListener(attributeValuePanel);
        
    }
    
    
    public Component getComponent() {
        return this;
    }
    
    public void refresh() {
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        setLayout(new BorderLayout(0, 0));
        
        JPanel panel = new JPanel();
        panel.setPreferredSize(new Dimension(10, 150));
        add(panel, BorderLayout.NORTH);
        panel.setLayout(null);
        jLabel2 = new javax.swing.JLabel();
        jLabel2.setBounds(10, 29, 80, 15);
        panel.add(jLabel2);
        
                jLabel2.setText(AppLocal.getIntString("label.locationname"));
                m_jName = new javax.swing.JTextField();
                m_jName.setBounds(90, 26, 260, 19);
                panel.add(m_jName);
                jLabel3 = new javax.swing.JLabel();
                jLabel3.setBounds(10, 55, 80, 15);
                panel.add(jLabel3);
                
                        jLabel3.setText(AppLocal.getIntString("label.locationaddress"));
                        m_jAddress = new javax.swing.JTextField();
                        m_jAddress.setBounds(90, 55, 260, 19);
                        panel.add(m_jAddress);
                        
                        isVirtual = new JCheckBox(AppLocal.getIntString("label.isVirtual"));
                        isVirtual.setBounds(90, 101, 140, 30);
                        panel.add(isVirtual);
                        
                        isCustomer = new JCheckBox(AppLocal.getIntString("label.isCustomer"));
                        isCustomer.setBounds(90, 76, 140, 23);
                        panel.add(isCustomer);
                        
                         jckPrefPrice = new JCheckBox(AppLocal.getIntString("label.prefPrice"));
                        jckPrefPrice.setBounds(245, 80, 103, 23);
                        panel.add(jckPrefPrice);
                        
                         jckScore = new JCheckBox(AppLocal.getIntString("label.score"));
                        jckScore.setBounds(245, 105, 103, 23);
                        panel.add(jckScore);

    }// </editor-fold>//GEN-END:initComponents
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JTextField m_jAddress;
    private javax.swing.JTextField m_jName;
    // End of variables declaration//GEN-END:variables

	@Override
	public void activate() throws BasicException {
		
	}
	@Override
	public Location createNew(Properties prop) {
		return new Location();
	}
	@Override
	public void rebuild(Location obj) throws BasicException {
		obj.setName(m_jName.getText());
		obj.setAddress(m_jAddress.getText());
		obj.setCustomer(isCustomer.isSelected());
		obj.setVirtual(isVirtual.isSelected());
		obj.setScore(jckScore.isSelected());
		obj.setPrefSell(jckPrefPrice.isSelected());
	}
	@Override
	public void updateUI(boolean editAble, int state) {
		m_jName.setText(obj.getName());
        m_jAddress.setText(obj.getAddress());
        isCustomer.setSelected(obj.isCustomer());
        isVirtual.setSelected(obj.isVirtual());
        jckScore.setSelected(obj.isScore());
        jckPrefPrice.setSelected(obj.isPrefSell());

        m_jName.setEnabled(editAble);
        m_jAddress.setEnabled(editAble);
        isCustomer.setEnabled(editAble);
        isVirtual.setEnabled(editAble);
        jckScore.setEnabled(editAble);
        jckPrefPrice.setEnabled(editAble);
	}
	
	@Override
	public Class getEditClass() {
		return Location.class;
	}
}
